const express = require("express");

const router = express.Router();

let mysqlquery = require("../db/mysql");

let data = {}

router.get('/users', async (req,res)=>{
    let getinfo = `select * from users`
    data = await mysqlquery(getinfo);
    console.log(data[1]);
    let userinfo = data[1]
    res.render("users.html",{userinfo});
})
router.get('/del',async (req,res)=>{
    let {username}  =await req.query;
    let getinfo = `delete from users where username = ${username}`;
    let [flag,data] = await mysqlquery(getinfo);
    if(flag)
    {
        res.send({status:400,msg:"删除成功"})
    }
    else
    {
        res.send({status:"500",msg:"删除失败"})
    }
})

module.exports = router;

